home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Think Class Libraries / WASTE TCL 2.0b2 / WASTEEdit / Aliases / WASTE TCL 2.0 ƒ / CWASTEDlgText.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-13  |  7.8 KB  |  332 lines  |  [TEXT/SPM ]

  1. /******************************************************************************
  2.  CWASTEDlgText.cpp
  3.  
  4.     A class with some of the functionality of CDialogText, but using CWASTEText
  5.  
  6.     by Dan Crevier
  7.     version 1.8
  8.  
  9.     Roms    95/11/08    adapted to THINK C / TCL 1.1.3
  10.  ******************************************************************************/
  11.  
  12. #ifdef TCL_PCH
  13. #include <TCLHeaders>
  14. #endif
  15.  
  16. #include "CWASTEDlgText.h"
  17. #include "CDialog.h"
  18. #include <CPaneBorder.h>
  19. #include "CBartender.h"
  20. #include "Constants.h"
  21. #include "CTextEditTask.h"
  22.  
  23. #define kBorderAmount    2    // white space between border and text of edit field
  24.  
  25. extern CBartender    *gBartender;
  26. extern CBureaucrat        *gGopher;        // First in line to get commands
  27.  
  28. static pascal void WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
  29.     long inputAreaEnd, long pinRangeStart, long pinRangeEnd);
  30.  
  31. #if (TCL_VERSION) >= 0x02000000
  32. TCL_DEFINE_CLASS_D1(CWASTEDlgText, CWASTEText);
  33. #endif
  34.  
  35. #ifndef THINK_C
  36. /********************************************************\
  37.  CWASTEDlgText - default constructor
  38. \********************************************************/
  39.  
  40. CWASTEDlgText::CWASTEDlgText()
  41. {
  42.     TCL_END_CONSTRUCTOR
  43. }
  44.  
  45.  
  46. /********************************************************\
  47.  CWASTEDlgText - constructor
  48. \********************************************************/
  49.  
  50. CWASTEDlgText::CWASTEDlgText(
  51.     CView            *anEnclosure,
  52.     CBureaucrat        *aSupervisor,
  53.     short            aWidth,
  54.     short            aHeight,
  55.     short            aHEncl,
  56.     short            aVEncl,
  57.     SizingOption    aHSizing,
  58.     SizingOption    aVSizing,
  59.     short            aLineWidth,
  60.     Boolean        aScrollHoriz,
  61.     Boolean        aIsRequired,
  62.     long            aMaxValidLength,
  63.     Boolean        aValidateOnResign,
  64.     Boolean        supportObjects,
  65.     Boolean        supportUndo,
  66.     Boolean        supportDragAndDrop,
  67.     Boolean        outlineHighliting,
  68.     Boolean        drawOffscreen)
  69.  
  70.     : CWASTEText(anEnclosure, aSupervisor,
  71.         aWidth, aHeight, aHEncl, aVEncl,
  72.         aHSizing, aVSizing, aLineWidth, aScrollHoriz, NULL, supportObjects,
  73.         supportUndo, supportDragAndDrop, outlineHighliting, drawOffscreen)
  74. {
  75.  
  76.     IWASTEDlgTextX();
  77.     TCL_END_CONSTRUCTOR
  78. }
  79.  
  80.  
  81. /********************************************************\
  82.  ~CWASTEDlgText - destructor
  83. \********************************************************/
  84.  
  85. CWASTEDlgText::~CWASTEDlgText()
  86. {
  87.     TCL_START_DESTRUCTOR
  88. }
  89.  
  90. #endif    // THINK_C
  91.  
  92. /********************************************************\
  93.  IWASTEDlgText - initializer, if used with default
  94.      constructor
  95. \********************************************************/
  96.  
  97. void CWASTEDlgText::IWASTEDlgText(CView *anEnclosure, CBureaucrat *aSupervisor,
  98.                 short aWidth, short aHeight,
  99.                 short aHEncl, short aVEncl,
  100.                 SizingOption aHSizing, SizingOption aVSizing,
  101.                 short aLineWidth)
  102. {
  103.     CWASTEText::IWASTEText(anEnclosure, aSupervisor,
  104.         aWidth, aHeight, aHEncl, aVEncl,
  105.         aHSizing, aVSizing, aLineWidth
  106. #ifdef THINK_C
  107.         ,
  108.         NULL,
  109.         true,
  110.         true,
  111.         true,
  112.         true,
  113.         false
  114. #endif // THINK_C
  115.         );
  116.  
  117.     IWASTEDlgTextX();
  118. }
  119.  
  120.  
  121. /********************************************************\
  122.  IViewTemp - construct from View resource
  123. \********************************************************/
  124.  
  125. void CWASTEDlgText::IViewTemp(CView *anEnclosure, CBureaucrat *aSupervisor,
  126.                             Ptr viewData)
  127. {
  128.     CWASTEText::IViewTemp(anEnclosure, aSupervisor, viewData);
  129.  
  130.     IWASTEDlgTextX();
  131. }
  132.  
  133.  
  134. /********************************************************\
  135.  IWASTEDlgTextX - common initialization
  136. \********************************************************/
  137.  
  138. void CWASTEDlgText::IWASTEDlgTextX()
  139. {
  140. #if WASTE_VERSION >= 0x01100000
  141.     static WETSMPostUpdateUPP    postProc = NULL;
  142. #else
  143.     WETSMPostUpdateProcPtr postProc;
  144. #endif
  145.  
  146.     MakeBorder();
  147.     SetWholeLines(FALSE);
  148.     
  149.     // set postupdate routine to WEPostUpdate
  150. #if WASTE_VERSION >= 0x01100000
  151.     if (postProc == NULL)
  152.         postProc = NewWETSMPostUpdateProc(WEPostUpdate);
  153. #else
  154.     postProc = &WEPostUpdate;
  155. #endif
  156.     WESetInfo(weTSMPostUpdate, (Ptr)&postProc, macWE);
  157.     
  158.     Specify(kEditable, kSelectable, kNotStylable);
  159. }
  160.  
  161. /********************************************************\
  162.  WEPostUpdate -- broadcast a dialog text changed message
  163. \********************************************************/
  164.  
  165.  pascal void CWASTEDlgText::WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
  166.     long inputAreaEnd, long pinRangeStart, long pinRangeEnd)
  167. {
  168.     short ID;
  169.     GrafPtr curPort;
  170.     CWASTEText *itsOwner = NULL;
  171.  
  172.     WEGetInfo(weRefCon, (Ptr)&itsOwner, hWE);
  173. #if (TCL_VERSION) >= 0x02000000
  174.     TCL_ASSERT_OBJECT_PTR(itsOwner);
  175.     TCL_ASSERT(member(itsOwner, CWASTEText));
  176. #else
  177.     ASSERT(member(itsOwner, CWASTEText));
  178. #endif
  179.     
  180.     CWASTEText::WEPostUpdate(hWE, fixLength, inputAreaStart, inputAreaEnd, pinRangeStart,
  181.         pinRangeEnd);
  182.         
  183.     if (itsOwner != NULL && inputAreaStart == -1 && inputAreaEnd == -1)
  184.     {
  185.         GetPort(&curPort);
  186.         ID = itsOwner->ID;
  187.         itsOwner->BroadcastChange(dialogTextChanged, &ID);
  188.         SetPort(curPort);
  189.         itsOwner->Prepare();
  190.     }
  191. }
  192.  
  193.  
  194. /********************************************************\
  195.  MakeBorder - put a border around the text
  196. \********************************************************/
  197.  
  198. void CWASTEDlgText::MakeBorder()
  199. {
  200.     Rect    margin;
  201.     CPaneBorder *border;
  202.  
  203. #if (TCL_VERSION) >= 0x02000000
  204.     border = TCL_NEW(CPaneBorder,());
  205. #else
  206.     border = new (CPaneBorder);
  207. #endif
  208.  
  209.     border->IPaneBorder(kBorderFrame);
  210.     SetRect(&margin, -kBorderAmount, -kBorderAmount, kBorderAmount, kBorderAmount);
  211.     border->SetMargin(&margin);
  212.     SetBorder(border);
  213. }
  214.  
  215. /********************************************************\
  216.  DoKey - handle Tab and Return
  217. \********************************************************/
  218.  
  219. void CWASTEDlgText::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
  220. {
  221.     Boolean pass = TRUE;
  222.     short    ID;
  223.  
  224.     switch (theChar)
  225.     {
  226.         case '\t':
  227.         case '\r':
  228.         case kEnterKey:
  229.             pass = FALSE;
  230.             break;
  231.  
  232.         case kEscapeOrClear:
  233.             if (keyCode == KeyEscape) pass = FALSE;
  234.             break;
  235.     }
  236.     if (pass)
  237.     {
  238.         CWASTEText::DoKeyDown(theChar, keyCode, macEvent);
  239.  
  240. #if WASTE_VERSION >= 0x01100000
  241.         { // I'm not sure of the right thing to do here -- check mod counts?
  242. #else
  243.         if (itsTypingTask && itsTypingTask->CanStillType())
  244.         {
  245. #endif
  246.             ID = this->ID;
  247.             BroadcastChange(dialogTextChanged, &ID);
  248.         }
  249.     }
  250.     else
  251.         itsSupervisor->DoKeyDown(theChar, keyCode, macEvent);
  252. }
  253.  
  254. /********************************************************\
  255.  GetTextString - return the text as a pascal string
  256. \********************************************************/
  257.  
  258. void CWASTEDlgText::GetTextString(StringPtr aString)
  259. {
  260.     short length = Min(GetLength(), 255);
  261.  
  262.     StopInlineSession();
  263.     BlockMove(*GetTextHandle(), &aString[1], length);
  264.     aString[0] = length;
  265. }
  266.  
  267. /********************************************************\
  268.  PerformEditCommand - handle cut, copy, paste, and clear
  269.      -- check for text changed
  270. \********************************************************/
  271.  
  272. void CWASTEDlgText::PerformEditCommand(long theCommand)
  273. {
  274.     short    ID;
  275.  
  276.     CWASTEText::PerformEditCommand(theCommand);
  277.  
  278.     switch( theCommand)
  279.     {        
  280.         case cmdCut:
  281.         case cmdPaste:
  282.         case cmdClear:
  283.             ID = this->ID;
  284.             BroadcastChange(dialogTextChanged, &ID);
  285.             break;
  286.         
  287.         default:
  288.             break;
  289.     }
  290.  
  291. }
  292.  
  293. #if VA_COMPATIBLE_IO
  294.  
  295. /******************************************************************************
  296.  PutTo
  297.         Put the contents of this object to the stream
  298.  ******************************************************************************/
  299.  
  300. void CWASTEDlgText::PutTo(CStream& stream)
  301. {
  302. #ifdef TCL_OBJECT_IO
  303.     // write made up values
  304.     stream << (long)0 << (Boolean) false << (Boolean) false;
  305.     CWASTEText::PutTo(stream);
  306. #endif
  307. }
  308.  
  309.  
  310. /******************************************************************************
  311.  GetFrom
  312.  
  313.         Get the contents of this object from the stream and
  314.         initialize the object
  315.  ******************************************************************************/
  316.  
  317. void CWASTEDlgText::GetFrom(CStream& stream)
  318. {
  319. #ifdef TCL_OBJECT_IO
  320.     Boolean required, validate;
  321.     long maxValidLength;
  322.  
  323.     // note, values are ignored
  324.     stream >> maxValidLength >> required >> validate;
  325.  
  326.     CWASTEText::GetFrom(stream);
  327.     
  328.     IWASTEDlgTextX();
  329. #endif
  330. }
  331.  
  332. #endif // VA_COMPATIBLE_IO